package com.stormragetech.teamwork.spring.config;

import com.stormragetech.teamwork.spring.interceptor.LoginInterceptor;
import com.stormragetech.teamwork.module.user.spring.redis.RedisDao;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.util.Assert;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * description: //TODO
 *
 * @author: Xue Bin
 * @version: 1.0.0-SNAPSHOT
 */
@Log4j2
//@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    private final RedisDao redisDao;

    @Autowired
    public InterceptorConfig(RedisDao redisDao) {
        Assert.notNull(redisDao, "RedisDao cannot be null !!!");
        this.redisDao = redisDao;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("caoniama1");
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/**");
        super.addInterceptors(registry);
        log.info("caoniama2");
    }

    @Bean
    LoginInterceptor loginInterceptor() {
        return new LoginInterceptor(redisDao);
    }

}
